<?php

namespace IDock\Insurance\DAJIA\Response;

use Exception;
use IDock\Http\Response;
use IDock\Insurance\DAJIA\DAJIAEnums;
use IDock\Insurance\DAJIA\Response\AllDAJIAResponse;
use IDock\Printer\NonCar\NonCarUnderwritingPrinter;
use IDock\Printer\Premium\PremiumBIPrinter;
use IDock\Printer\Premium\PremiumCIPrinter;
use IDock\Printer\Premium\PremiumCoveragePrinter;
use IDock\Printer\Premium\PremiumInquiryPrinter;
use IDock\Printer\Premium\PremiumTaxPrinter;
use IDock\Printer\PremiumUnderwritingPrinter;
use IDock\Printer\VehiclePrinter;

class InsuranceConfirmResponse extends AllDAJIAResponse
{
    public function printerInit(): Response
    {
        $premiumUnderwritingPrinter = new PremiumUnderwritingPrinter();
        $nonCarUnderwritingPrinter = new NonCarUnderwritingPrinter();

        $data = $this->get('body',[]);

        if($data['status'] == '0003'){
            //核保失败
            $premiumUnderwritingPrinter->statusCode = 'U2';
            $premiumUnderwritingPrinter->messageTip = $data['message'];
            $premiumUnderwritingPrinter->noCarUnderwritingPrinter = $nonCarUnderwritingPrinter;
            $this->printer = $premiumUnderwritingPrinter;
            return $this;
        }

        $premiumUnderwritingPrinter->statusCode = 'U1';
        if($data['result']['jqAppStatus'] == '2' && $data['result']['syAppStatus'] == '2'){
            $premiumUnderwritingPrinter->statusCode = 'U1';
        }
        $msg = [];
        if($data['result']['jqAppStatus'] == '1'){
            $msg[] = $data['result']['jqAppStatusMessage'];
            $premiumUnderwritingPrinter->statusCode = 'U3';
        }
        if($data['result']['syAppStatus'] == '1'){
            $msg[] = $data['result']['syAppStatusMessage'];
            $premiumUnderwritingPrinter->statusCode = 'U3';
        }
        if(!empty($msg)){
            $premiumUnderwritingPrinter->messageTip = implode("\r\n",$msg);
        }
        $premiumUnderwritingPrinter->ciInquiryNo = $data['result']['jqProposalNo'];
        $premiumUnderwritingPrinter->biInquiryNo = $data['result']['syProposalNo'];
        $premiumUnderwritingPrinter->noCarUnderwritingPrinter = $nonCarUnderwritingPrinter;
        $this->printer = $premiumUnderwritingPrinter;
        return $this;
    }
}
